import requests
from lxml import etree
import re

url = 'https://movie.douban.com/review/13523241/'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko'}

html_response = requests.get(url, headers=headers)
html_content = html_response.content.decode('utf8')
print(html_content)

html = etree.HTML(html_content)
movie = {}
# 标题
t_title = html.xpath('//div[@class="subject-title"]/a/text()')[0]  # > 山河令生来知己演唱会
title = re.findall(r'\w+', t_title)[0]
# 评论人
reviewer = html.xpath('//header/a/span/text()')[0]
# 评分
score = html.xpath('//header/span[@class="allstar50 main-title-rating"]/@title')[0]
# 品论
comment_list = html.xpath('//div[@class="review-content clearfix"]/p/text()')
comment_str = ''.join(comment_list)
comment = re.sub(r'\s+', '，', comment_str)

movie = {
    'title': title,
    'reviewer': reviewer,
    'score': score,
    'comment': comment,
}
print(movie)
